<?php


namespace app\cms\model;


use app\cms\community\lib\QueryModel;
use app\cms\dto\siteInfo;
use iflow\Response;

class siteModel extends QueryModel
{

    protected $table = "site_table";

    public static function getSiteInfo(): Response
    {
        $site = static::where([
            'siteId' => 1
        ]) -> cache(true) -> findOrEmpty();
        if ($site -> isExists()) {
            return message() -> success('获取站点信息成功', $site -> toArray());
        }
        return message() -> nodata('暂无站点信息');
    }

    public function updateSiteInfo(siteInfo $siteInfo)
    {
        $info = (array)$siteInfo;
        unset($info['siteId']);
        $info = array_change_key_case($info, CASE_LOWER);

        $site = $this -> where([
            'siteId' => 1
        ]) -> findOrEmpty();

        if ($site -> isExists()) {
            $site = $this
                -> cache('update_time')
                -> where([
                    'siteId' => 1
                ]) -> update($info);
            if ($site) {
                return message() -> success('更新站点信息成功', $info);
            }
        }
        return message() -> success('更新站点信息成功', self::create($info) -> toArray());
    }

}